package com.lazybones.base.engineer.common.conf.minio;

import io.minio.MinioClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConfigurationProperties(prefix = "application-minio")
public class MinioConfig {
    private final Logger log = LoggerFactory.getLogger(MinioConfig.class);
    @Value(value = "${minio.access-Key}")
    private String accessKey;
    @Value(value = "${minio.secret-Key}")
    private String secretKey;
    @Value(value = "${minio.url}")
    private String url;
    @Value(value = "${minio.bucket-name}")
    private String bucketName;
    @Override
    public String toString() {
        return "MinioConfig{" +
                "accessKey='" + accessKey + '\'' +
                ", secretKey='" + secretKey + '\'' +
                ", url='" + url + '\'' +
                ", bucketName='" + bucketName + '\'' +
                '}';
    }
    @Bean
    public MinioClient minioClient(){
        return  MinioClient.builder().endpoint(url).credentials(accessKey, secretKey).build();
    }
    public String getBucketName(){
        log.info("已获取到数据：{}",bucketName);
        return bucketName;
    }
}
